package com.itheima.mapper;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface StudentMapper {
    List<Student> list(StudentQueryParam studentQueryParam);

    @Insert("insert into student (name,no,gender,phone,id_card,is_college,address,degree,graduation_date,clazz_id,create_time,update_time) " +
            "values (#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree},#{graduationDate},#{clazzId},#{createTime},#{updateTime})")
    void save(Student student);

    void delete(List<Integer> ids);

    @Select("select * from student where id = #{id}")
    Student findById(Integer id);

    void update(Student student);

    @Update("update student set violation_score = #{score},violation_count = violation_count + 1 where id = #{id}")
    void updateScore(Integer id, Integer score);

    @Select("select * from student where clazz_id = #{id}")
    List<Student> findStudentByClazzId(Integer id);
}
